package com.lagou.controller;

import com.lagou.pojo.Article;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/articles")
public class ArticleController {

    @Autowired
    private ArticleService articleService;

    @GetMapping("/toIndex")
    public String list(Model model,Integer currentPage,Integer pageSize){
        if(currentPage == null){
            currentPage = Integer.valueOf(0);
        }
        pageSize = Integer.valueOf(3);
        PageImpl<Article> page = (PageImpl<Article>) articleService.listAll(currentPage,pageSize);
        model.addAttribute("page",page);
        model.addAttribute("totalPages",page.getTotalPages());
        model.addAttribute("currentPage",currentPage);
        return "client/index";
    }
}
